#include <iostream>
#include <vector>
using namespace std;

int find_father(vector<int> &father, int x)
{
        return father[x] == x ? x : father[x] = find_father(father, father[x]);
}

void merge(vector<int> &father, int x, int y)
{
        int fx = find_father(father, x);
        int fy = find_father(father, y);
        if(fx != fy){
                father[fy] = fx;
        }
}

bool check(vector<int> &father, int x, int y)
{
        return find_father(father, x) == find_father(father, y);
}

int main()
{
	int n, m, p, x, y;

	scanf("%d%d", &n, &m);
	vector<int> father(n + 1);
	for(int i = 1; i <= n; i++){
		father[i] = i;
	}
	for(int i = 0; i < m; i++){
		scanf("%d%d", &x, &y);
                merge(father, x, y);
	}

	scanf("%d", &p);
	
	for(int i = 0; i < p; i++){
		scanf("%d%d", &x, &y);
		if(check(father, x, y)){
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}

	return 0;
}